import 'package:flutter/cupertino.dart';
import 'package:opnvpn_flutter/opnvpn_flutter.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'opnvpn_flutter_method_channel.dart';

abstract class OpnvpnFlutterPlatform extends PlatformInterface {
  /// Constructs a OpnvpnFlutterPlatform.
  OpnvpnFlutterPlatform() : super(token: _token);

  static final Object _token = Object();

  static OpnvpnFlutterPlatform _instance = MethodChannelOpnvpnFlutter();

  /// The default instance of [OpnvpnFlutterPlatform] to use.
  ///
  /// Defaults to [MethodChannelOpnvpnFlutter].
  static OpnvpnFlutterPlatform get instance => _instance;

  /// Platform-specific implementations should set this with their own
  /// platform-specific class that extends [OpnvpnFlutterPlatform] when
  /// they register themselves.
  static set instance(OpnvpnFlutterPlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  Future<String?> getPlatformVersion() {
    throw UnimplementedError('platformVersion() has not been implemented.');
  }

  ///This function should be called before any usage of OpenVPN
  ///All params required for iOS, make sure you read the plugin's documentation
  ///
  ///
  ///providerBundleIdentfier is for your Network Extension identifier
  ///
  ///localizedDescription is for description to show in user's settings
  ///
  ///
  ///Will return latest VPNStage
  Future<void> initialize({
    String? providerBundleIdentifier,
    String? localizedDescription,
    String? groupIdentifier,
    Function(VpnStatus status)? lastStatus,
    Function(VPNStage status)? lastStage,
  }) {
    throw UnimplementedError('initialize() has not been implemented.');
  }

  ///Connect to VPN
  ///
  ///config : Your openvpn configuration script, you can find it inside your .ovpn file
  ///
  ///name : name that will show in user's notification
  ///
  ///certIsRequired : default is false, if your config file has cert, set it to true
  ///
  ///username & password : set your username and password if your config file has auth-user-pass
  ///
  ///bypassPackages : exclude some apps to access/use the VPN Connection, it was List<String> of applications package's name (Android Only)
  void connect(String config, String name,
      {String? username,
      String? password,
      List<String>? bypassPackages,
      bool certIsRequired = false}) async {
    throw UnimplementedError('connect() has not been implemented.');
  }

  ///Disconnect from VPN
  void disconnect() {
    throw UnimplementedError('disconnect() has not been implemented.');
  }

  ///Check if connected to vpn
  Future<bool> isConnected() async =>
      stage().then((value) => value == VPNStage.connected);

  ///Get latest connection stage
  Future<VPNStage> stage() async {
    throw UnimplementedError('stage() has not been implemented.');
  }

  ///Get latest connection status
  Future<VpnStatus?> status() {
    throw UnimplementedError('status() has not been implemented.');
  }

  ///Request android permission (Return true if already granted)
  Future<bool> requestPermissionAndroid() async {
    throw UnimplementedError(
        'requestPermissionAndroid() has not been implemented.');
  }

  ///Sometimes config script has too many Remotes, it cause ANR in several devices,
  ///This happened because the plugin check every remote and somehow affected the UI to freeze
  ///
  ///Use this function if you wanted to force user to use 1 remote by randomize the remotes provided
  static Future<String?> filteredConfig(String? config) async {
    throw UnimplementedError(
        'requestPermissionAndroid() has not been implemented.');
  }
}
